package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TActivityUser;
import com.ruoyi.system.service.ITActivityUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动人员Controller
 * 
 * @author yyh
 * @date 2024-06-24
 */
@RestController
@RequestMapping("/system/activityUser")
public class TActivityUserController extends BaseController
{
    @Autowired
    private ITActivityUserService tActivityUserService;

    /**
     * 查询活动人员列表
     */
    @PreAuthorize("@ss.hasPermi('system:activityUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(TActivityUser tActivityUser)
    {
        startPage();
        List<TActivityUser> list = tActivityUserService.selectTActivityUserList(tActivityUser);
        return getDataTable(list);
    }

    /**
     * 导出活动人员列表
     */
    @PreAuthorize("@ss.hasPermi('system:activityUser:export')")
    @Log(title = "活动人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TActivityUser tActivityUser)
    {
        List<TActivityUser> list = tActivityUserService.selectTActivityUserList(tActivityUser);
        ExcelUtil<TActivityUser> util = new ExcelUtil<TActivityUser>(TActivityUser.class);
        util.exportExcel(response, list, "活动人员数据");
    }

    /**
     * 获取活动人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:activityUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tActivityUserService.selectTActivityUserById(id));
    }

    /**
     * 新增活动人员
     */
    @PreAuthorize("@ss.hasPermi('system:activityUser:add')")
    @Log(title = "活动人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TActivityUser tActivityUser)
    {
        if(tActivityUser.getUserId()==null){
            LoginUser loginUser = getLoginUser();
            tActivityUser.setUserId(loginUser.getUserId());
        }
        return toAjax(tActivityUserService.insertTActivityUser(tActivityUser));
    }

    /**
     * 修改活动人员
     */
    @PreAuthorize("@ss.hasPermi('system:activityUser:edit')")
    @Log(title = "活动人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TActivityUser tActivityUser)
    {
        return toAjax(tActivityUserService.updateTActivityUser(tActivityUser));
    }

    /**
     * 删除活动人员
     */
    @PreAuthorize("@ss.hasPermi('system:activityUser:remove')")
    @Log(title = "活动人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tActivityUserService.deleteTActivityUserByIds(ids));
    }
}
